/**
 * Copyright (c) 2015 Baidu. All Rights Reserved.
 *
 * @file 用于打包输出文件夹
 * @author yuanguozheng
 */
var config = require('./config');
var path = require('path');
var fs = require('fs');
var fse = require('fs-extra');
var zipFolder = require('zip-folder');

/**
 * 打包输出的源代码
 */
function doPackage(proj, lang, callback) {
    var p1 = path.join(__dirname, '../' + config.projectConfig('path') + '/sources/' + lang + '/' + proj);
    var p2 = path.join(__dirname, '../' + config.projectConfig('path') + '/' + proj + '.zip');
    zipFolder(p1, p2,
        function (err) {
            if (err) {
                console.error('打包失败');
                console.error(err);
                callback(undefined);
            }
            fse.removeSync(p1);
            callback(p2);
        }
    );
}

module.exports = doPackage;